﻿using D.Medicalcare.Domain.Entities;
using D.Medicalcare.ErrorCode;
using D.Medicalcare.Infrastructure.Interfaces;
using D.Medicalcare.Read.API.Application.Command.DepartmentCommand;
using MediatR;

namespace D.Medicalcare.Read.API.Application.Handler.DepartmentHarder
{
    public class ChildDepartmentHarder : IRequestHandler<ChildDepartmentCommand, APIResult<List<Department>>>
    {


        private readonly IBaseRepository<Department> repository;

        public ChildDepartmentHarder(IBaseRepository<Department> baseRepository)
        {
            this.repository = baseRepository;
        }

        public async Task<APIResult<List<Department>>> Handle(ChildDepartmentCommand request, CancellationToken cancellationToken)
        {
            try
            {
                APIResult<List<Department>> result = new APIResult<List<Department>>();
                result.Code = APIEnum.Mvc;
                result.Msg = "查询成功";
                var list = repository.GetAll().Where(x => x.SuperAffiliation == request.DeparId).ToList();
                result.Data= list;

                return await Task.FromResult(result);
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
